Skip to content

fix(core): use a queue to process events in event routes#18259

Merged
jlongster merged 2 commits intodevfrom
jlongster/event-route-queue
Mar 19, 2026
Merged

fix(core): use a queue to process events in event routes#18259
jlongster merged 2 commits intodevfrom
jlongster/event-route-queue

Conversation

@jlongster
Copy link
Contributor

  • Moves the /event route into it's own file
  • Handle event processing more explicitly. Previously, it was doing await stream.writeSSE inside of a callback to Bus.subscribeAll. The Bus abstraction allows you to do await Bus.publish and it will actually wait for all listeners to finish processing, and since a listener is writing to SSE, it will block until the event is written to SSE
  • However, that's a little strange, and is unpredictable because multiple paths could be publishing events through the bus. So it looks like it's writing events to SSE in order, but that's not actually guaranteed
  • We aren't able to actually allow waiting when publishing events anymore. With the new sync system, it will handle emitting a lot of events internally
  • We still should queue writing events to SSE. This PR does that by using effect's queue mechanism, pushing events as they come onto the queue and then sequentially processing them

@jlongster jlongster force-pushed the jlongster/event-route-queue branch from 36be614 to f3ceefd Compare March 19, 2026 16:36
for (const key of [def.type, "*"]) {
const match = state().subscriptions.get(key)
for (const sub of match ?? []) {
const match = [...(state().subscriptions.get(key) ?? [])]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needed because there was a bug before where if you unsubscribed in a handler synchronously, it mutates this same array so it'll skip the next listener

@jlongster jlongster requested a review from adamdotdevin as a code owner March 19, 2026 17:22
@jlongster jlongster force-pushed the jlongster/event-route-queue branch from bdb6673 to 25a2827 Compare March 19, 2026 17:30
@jlongster jlongster merged commit 0540751 into dev Mar 19, 2026
6 of 8 checks passed
@jlongster jlongster deleted the jlongster/event-route-queue branch March 19, 2026 17:51
filipeandre pushed a commit to filipeandre/opencode that referenced this pull request Mar 19, 2026
raf1hh pushed a commit to raf1hh/opencode that referenced this pull request Mar 20, 2026
pengzha0 pushed a commit to pengzha0/dwtcode that referenced this pull request Mar 20, 2026
demostanis pushed a commit to demostanis/opencode that referenced this pull request Mar 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant